﻿using System.IO;
using System.Configuration;
using Rio.Framework.RioManager;
using Rio.Workflow.WCF.Helpers;

namespace Rio.Workflow.WCF.Configuration
{
    public class SettingsManager
    {
        public static bool Init()
        {
            // Retreive path for configuration application
            string l_sConfiguration = ConfigurationManager.AppSettings.Get("Rio.Applications.Web.Configuration");
            if (string.IsNullOrEmpty(l_sConfiguration))
            {
                l_sConfiguration = ConfigurationHelper.GetEnvironnementPath() + "Rio.Applications.Web.Config";
            }

            string l_sDirectoryDA = Path.GetDirectoryName(l_sConfiguration);
            string l_sFileNameDA = Path.GetFileName(l_sConfiguration);

            // Retreive alias for DataBase connection
            string l_sDataBaseConnectionDA = ConfigurationManager.AppSettings.Get("Rio.Applications.Web.DataBaseConnection");

            // Retrieve the default culture
            string l_sDefaultCulture = ConfigurationManager.AppSettings.Get("Rio.Applications.Web.DefaultCulture");

            // Initialise the Manager
            if (MainManager.Init(l_sDirectoryDA, l_sFileNameDA, l_sDataBaseConnectionDA, l_sDefaultCulture, null) == false)
            {
                LoggerManager.GetBusinessLogger.LogError("() Unable to load a good configuration so exit process!!!");
                return false;
            }

            // First Trace
            LoggerManager.GetBusinessLogger.LogInfo(string.Empty);
            return true;
        }
    }
}